package org.mcclone.cas.authentication;

import org.apereo.cas.authentication.AuthenticationEventExecutionPlanConfigurer;
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory;
import org.apereo.cas.configuration.CasConfigurationProperties;
import org.apereo.cas.services.ServicesManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author McClone
 * @see org.apereo.cas.adaptors.jdbc.config.CasJdbcAuthenticationConfiguration
 */
@Configuration("authenticationConfigurer")
@EnableConfigurationProperties(CasConfigurationProperties.class)
public class AuthenticationConfiguration {
    private static final Logger logger = LoggerFactory.getLogger(AuthenticationConfiguration.class);

    @Autowired
    @Qualifier("servicesManager")
    private ServicesManager servicesManager;

    /**
     * 设置自己的认证机制
     */
    @Bean
    public AuthenticationEventExecutionPlanConfigurer authenticationEventExecutionPlanConfigurer() {
        return plan -> {
            CustomAuthenticationHandler handler = new CustomAuthenticationHandler(CustomAuthenticationHandler.class.getSimpleName(),
                    servicesManager, new DefaultPrincipalFactory(), 10);
            plan.registerAuthenticationHandler(
                    handler);
            logger.info("Register CustomAuthenticationHandler For CAS.");
        };
    }




}
